import django_filters

from merchants.models import MerchantBill, WaivePaymentMerchant, MerchantMonthlyBill
from orders.models import OrderInfo, Express, OrderGoods
from goods.models import Goods


class MerchantBillFilter(django_filters.rest_framework.FilterSet):
    '''账单过滤'''

    bill_state = django_filters.BaseInFilter(field_name='bill_state', lookup_expr='in')
    business_no = django_filters.BaseInFilter(field_name='merchant__wyfMerchantID', lookup_expr='in')

    class Meta:
        model = MerchantBill
        fields = ('bill_state', 'business_no')


class WaivePaymentMerchantFilter(django_filters.rest_framework.FilterSet):
    '''账单过滤'''

    business_no = django_filters.BaseInFilter(field_name='business_no', lookup_expr='in')

    class Meta:
        model = WaivePaymentMerchant
        fields = ('business_no', )


class OrderInfoFilter(django_filters.rest_framework.FilterSet):
    '''订单过滤'''

    bill_id = django_filters.BaseInFilter(field_name='bill_id', lookup_expr='in')
    business_no = django_filters.BaseInFilter(field_name='merchant__wyfMerchantID', lookup_expr='in')
    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    order_species = django_filters.BaseInFilter(field_name='order_species', lookup_expr='in')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')

    class Meta:
        model = OrderInfo
        fields = ('bill_id', 'business_no', 'create_time_begin', 'create_time_end', 'state', 'order_species')


class GoodsFilter(django_filters.rest_framework.FilterSet):

    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    is_use_point = django_filters.BaseInFilter(field_name='is_use_point', lookup_expr='in')
    price_min = django_filters.NumberFilter(field_name="price", lookup_expr='gte')
    price_max = django_filters.NumberFilter(field_name="price", lookup_expr='lte')
    business_no = django_filters.BaseInFilter(field_name='merchant__wyfMerchantID', lookup_expr='in')
    is_launched = django_filters.BaseInFilter(field_name='is_launched', lookup_expr='in')

    class Meta:
        model = Goods
        fields = ('merchant_id', 'is_use_point', 'is_launched', 'price_min', 'price_max', 'business_no')


class MerchantMonthlyBillFilter(django_filters.rest_framework.FilterSet):

    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    settlement_amount_min = django_filters.NumberFilter(field_name="settlement_amount", lookup_expr='gte')
    settlement_amount_max = django_filters.NumberFilter(field_name="settlement_amount", lookup_expr='lte')
    business_no = django_filters.BaseInFilter(field_name='merchant__wyfMerchantID', lookup_expr='in')
    receipts_time_begin = django_filters.DateTimeFilter(field_name="receipts_time__date", lookup_expr='gte')
    receipts_time_end = django_filters.DateTimeFilter(field_name="receipts_time__date", lookup_expr='lte')

    class Meta:
        model = MerchantMonthlyBill
        fields = ('settlement_amount_min', 'settlement_amount_min', 'merchant_id', 'business_no', 'receipts_time_begin', 'receipts_time_end')


class ExpressFilter(django_filters.rest_framework.FilterSet):

    deliverystatus = django_filters.BaseInFilter(field_name='deliverystatus', lookup_expr='in')
    # nature = django_filters.BaseInFilter(field_name='nature', lookup_expr='in')
    order_id = django_filters.BaseInFilter(field_name='expressorderrelevance__order_id', lookup_expr='in')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    sign_time_begin = django_filters.DateTimeFilter(field_name="sign_time__date", lookup_expr='gte')
    sign_time_end = django_filters.DateTimeFilter(field_name="sign_time__date", lookup_expr='lte')

    class Meta:
        model = Express
        fields = ('deliverystatus', 'create_time_begin', 'create_time_end', 'sign_time_begin', 'sign_time_end', 'order_id')


class OrderGoodsFilter(django_filters.rest_framework.FilterSet):

    is_commented = django_filters.BaseInFilter(field_name='is_commented', lookup_expr='in')
    goods_id = django_filters.BaseInFilter(field_name='goods_id', lookup_expr='in')

    class Meta:
        model = OrderGoods
        fields = ('is_commented', 'goods_id')